//@ts-nocheck
import axios from 'axios'
import ElMessage from 'element-plus'

let request = axios.create({
    baseURL: import.meta.env.VITE_SERVER_URL
})

// 请求拦截器
request.interceptors.request.use((config) => {
    return config
})

// 响应拦截器
request.interceptors.response.use((response) => {
    return response.data
}, (error) => {
    let message = ''
    const status = error.response.status
    switch (status) {
        case 401:
            message = 'TOKEN过期'
            break
        case 403:
            message = '没有访问权限'
            break
        case 404:
            message = '访问的地址不存在'
            break
        case 500:
            message = '服务器在摸鱼'
            break
        default:
            message = '出现了未知的问题'
            break
    }
    ElMessage({
        type: 'error',
        message
    })
    return Promise.reject(error)
})

export default request